﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Configuration;
using System.Collections.Generic;
using System.Management.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;

namespace EntLibContrib.Query.Configuration.Manageability.Parameters
{
	/// <summary>
	/// Represents the configuration information for an instance of
	/// <see cref="EntLibContrib.Query.Configuration.DataSetParameterData"/>.
	/// </summary>
	/// <seealso cref="EntLibContrib.Query.Configuration.ParameterData"/>
	/// <seealso cref="NamedConfigurationSetting"/>
	/// <seealso cref="ConfigurationSetting"/>
	[ManagementEntity]
	public partial class DataSetParameterSetting : ParameterSetting
	{
		#region Fields
		private string dbType;
		private string direction;
		private string column;
		private string version;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the type of the db.
		/// </summary>
		/// <value>The type of the db.</value>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db"), ManagementConfiguration]
		public string DbType
		{
			get { return dbType; }
			set { dbType = value; }
		}

		/// <summary>
		/// Gets or sets the direction.
		/// </summary>
		/// <value>The direction.</value>
		[ManagementConfiguration]
		public string Direction
		{
			get { return direction; }
			set { direction = value; }
		}

		/// <summary>
		/// Gets or sets the column.
		/// </summary>
		/// <value>The column.</value>
		[ManagementConfiguration]
		public string Column
		{
			get { return column; }
			set { column = value; }
		}

		/// <summary>
		/// Gets or sets the version.
		/// </summary>
		/// <value>The version.</value>
		[ManagementConfiguration]
		public string Version
		{
			get { return version; }
			set { version = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="DataSetParameterSetting"/> class.
		/// </summary>
		/// <param name="sourceElement">The source element.</param>
		/// <param name="name">The parameter name.</param>
		/// <param name="dbType">The parameter data type.</param>
		/// <param name="direction">The parameter direction.</param>
		/// <param name="column">The column.</param>
		/// <param name="version">The version.</param>
		public DataSetParameterSetting(DataSetParameterData sourceElement,
																	string name,
																	string dbType,
																	string direction,
																	string column,
																	string version)
			: base(sourceElement, name)
		{
			this.dbType = dbType;
			this.direction = direction;
			this.column = column;
			this.version = version;
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns the <see cref="DataSetParameterSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The command name.</param>
		/// <returns>
		/// The published <see cref="DataSetParameterSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static DataSetParameterSetting BindInstance(string applicationName,
																											 string sectionName,
																											 string name)
		{
			return BindInstance<DataSetParameterSetting>(applicationName, sectionName, name);
		}

		/// <summary>
		/// Returns an enumeration of the published <see cref="DataSetParameterSetting"/> instances.
		/// </summary>
		/// <returns>Enumerable list of <see cref="DataSetParameterSetting"/> instances</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate"), ManagementEnumerator]
		public static IEnumerable<DataSetParameterSetting> GetInstances()
		{
			return GetInstances<DataSetParameterSetting>();
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Saves the changes on the <see cref="DataSetParameterSetting"/> to its corresponding configuration object.
		/// </summary>
		/// <param name="sourceElement">The configuration object on which the changes must be saved.</param>
		/// <returns>
		/// 	<see langword="true"/> if changes have been saved, <see langword="false"/> otherwise.
		/// </returns>
		/// <remarks>Must be overridden by subclasses to perform the actual save.</remarks>
		protected override bool SaveChanges(ConfigurationElement sourceElement)
		{
			return DataSetParameterDataWmiMapper.SaveChanges(this, sourceElement);
		}
		#endregion
	}
}
